package com.yzy.domain.strategy.repository;

import java.util.List;
import java.util.Map;

import com.yzy.domain.strategy.model.entity.StrategyAwardEntity;
import com.yzy.domain.strategy.model.entity.StrategyEntity;
import com.yzy.domain.strategy.model.entity.StrategyRuleEntity;
import com.yzy.domain.strategy.model.valobj.RuleTreeVO;
import com.yzy.domain.strategy.model.valobj.StrategyAwardRuleModelVO;
import com.yzy.domain.strategy.model.valobj.StrategyAwardStockKeyVO;

/**
 * @author yangzhenyu05 <yangzhenyu05@kuaishou.com>
 * Created on 2023-12-24
 * @description 策略仓储类接口
 */
public interface IStrategyRepository {
    /**
     * 根据策略Id查询策略奖品配置
     *
     * @param strategyId 策略Id
     * @return 策略奖品配置集合
     */
    List<StrategyAwardEntity> queryStrategyAwardList(Long strategyId);

    /**
     * 存储概率表、概率范围
     *
     * @param key                          Redis Key
     * @param rateRange                    概率范围值
     * @param strategyAwardSearchRateTable 概率范围查找表
     */

    void storeStrategyAwardSearchRateTable(String key, Integer rateRange,
                                           Map<Integer, Integer> strategyAwardSearchRateTable);

    /**
     * 从概率表中获取奖品ID
     *
     * @param key     key
     * @param rateKey 概率范围Key
     * @return 奖品ID
     */
    Integer getStrategyAwardAssemble(String key, Integer rateKey);

    /**
     * 获取概率范围
     *
     * @param strategyId 策略ID
     * @return 概率范围
     */
    int getRateRange(Long strategyId);

    /**
     * 获取概率范围
     *
     * @param key 根据key 获取
     * @return 概率范围
     */
    int getRateRange(String key);

    /**
     * 根据策略ID获取策略实体
     *
     * @param strategyId 策略ID
     * @return 策略实体
     */

    StrategyEntity queryStrategyEntityByStrategyId(Long strategyId);

    /**
     * 根据策略ID、ruleWeight 获取策略规则
     *
     * @param strategyId 策略ID
     * @param ruleModel  规则模式
     * @return 策略规则实体
     */
    StrategyRuleEntity queryStrategyRule(Long strategyId, String ruleModel);

    String queryStrategyRuleValue(Long strategyId, Integer awardId, String ruleModel);

    String queryStrategyRuleValue(Long strategyId, String ruleModel);

    StrategyAwardRuleModelVO queryStrategyAwardRuleModelVO(Long strategyId, Integer awardId);

    /**
     * 根据规则树ID，查询树结构信息
     *
     * @param treeId 规则树ID
     * @return 树结构信息
     */
    RuleTreeVO queryRuleTreeVOByTreeId(String treeId);

    /**
     * 缓存key，decr 方式扣减库存
     *
     * @param cacheKey 缓存Key
     * @return 扣减结果
     */

    Boolean subtractionAwardStock(String cacheKey);

    void awardStockConsumeSendQueue(StrategyAwardStockKeyVO build);

    StrategyAwardStockKeyVO takeQueueValue() throws InterruptedException;

    void updateStrategyAwardStock(Long strategyId, Integer awardId);
}
